package com.ysg.widget.dialog.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ysg.R;
import com.ysg.utils.YImageUtil;
import com.ysg.utils.YStringUtil;
import com.ysg.widget.dialog.entity.GiftListResult;

import java.util.List;

public class GiftAdapter extends BaseQuickAdapter<GiftListResult.GiftBean, BaseViewHolder> {
    private List<List<GiftListResult.GiftBean>> sumList;
    public GiftAdapter(List<List<GiftListResult.GiftBean>> sumList) {
        super(R.layout.item_dialog_gift);
        this.sumList = sumList;
    }

    @Override
    protected void convert(BaseViewHolder holder, GiftListResult.GiftBean item) {
        ImageView verticalImgView = holder.getView(R.id.verticalImgView);
        TextView verticalText = holder.getView(R.id.verticalText);
        TextView tv_gifsgoldmoney = holder.getView(R.id.tv_gifsgoldmoney);
        LinearLayout ll_giftXZLine = holder.getView(R.id.ll_giftXZLine);
        ImageView iv_zuanshiIcon = holder.getView(R.id.iv_zuanshiIcon);
        ImageView iv_jinbiIcon = holder.getView(R.id.iv_jinbiIcon);
        TextView tv_quanfuText = holder.getView(R.id.tv_quanfuText);

        YImageUtil.show(verticalImgView, item.getPicture());
        verticalText.setText(item.getGiftname());
        if (item.isGifItemPosition()) {
            ll_giftXZLine.setBackgroundResource(R.drawable.shape_red_radius_stroke);
        } else {
            ll_giftXZLine.setBackground(null);
        }
        if (YStringUtil.eq(1, item.getShifouquanfu())) {
            tv_quanfuText.setVisibility(View.VISIBLE);
        } else {
            tv_quanfuText.setVisibility(View.GONE);
        }
        if (YStringUtil.eq(1, item.getGoumaifangshi())) {//购买方式 钻石
            iv_zuanshiIcon.setVisibility(View.VISIBLE);
            iv_jinbiIcon.setVisibility(View.GONE);
        } else if (YStringUtil.eq(2, item.getGoumaifangshi())) {//金币
            iv_zuanshiIcon.setVisibility(View.GONE);
            iv_jinbiIcon.setVisibility(View.VISIBLE);
        }
        tv_gifsgoldmoney.setText(YStringUtil.removeZero(item.getGoldmoney() + ""));

        ll_giftXZLine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (List<GiftListResult.GiftBean> list: sumList){
                    for (GiftListResult.GiftBean data: list){
                        if (YStringUtil.eq(data.getId(), item.getId())){
                            data.setGifItemPosition(true);
                        }else{
                            data.setGifItemPosition(false);
                        }
                    }
                }
                notifyDataSetChanged();
            }
        });
    }
}
